﻿/*
 * File: TileSet.cs
 * Developer : Brent Larsen (brentoboy@gmail.com)
 * Date: 2011-AUG-13
 * Copyright (c) 2011 Brent Larsen.
 * Distributed under the terms of the GPL v3
 *  
 * This file is part of GenX-RPG
 * http://code.google.com/p/genx-rpg/ 
 * 
 * GenX-RPG is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GenX-RPG is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GenX-RPG.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rpg
{
    public class TileSet
    {
        public int Id { get; set; }
        public string UniqueId { get; set; }
        public string Name { get; set; }
        public string CopyrightOwner { get; set; }
        public string DateOriginallyPublished { get; set; }
        public string CopyrightNotice { get; set; }
        public string License { get; set; }

        //public string BitmapPath { get; set; }
        public byte[] BitmapData { get; set; }
        public int? Width { get; set; }
        public int? Height { get; set; }
        public List<Tile> Tiles { get; private set; }

        public TileSet()
        {
            this.Tiles = new List<Tile>();
        }

        public Tile GetTile(int x, int y)
        {
            if (x >= 0 && y >= 0)
            {
                var tile = Tiles.SingleOrDefault(t => t.BmpX / Tile.SQUARE_SIZE == x && t.BmpY / Tile.SQUARE_SIZE == y);
                if (tile == null)
                {
                    tile = new Tile(0, "", "", x, y, "", 0, 0, Tile.BLOCK_ALL);
                    Tiles.Add(tile);
                }
                return tile;
            }
            else
            {
                return null;
            }
        }

        public bool HasTile(int x, int y)
        {
            return Tiles.Any(t => t.BmpX / Tile.SQUARE_SIZE == x && t.BmpY / Tile.SQUARE_SIZE == y);
        }
    }
}
